#ifndef _test_SDPCommunicator_h
#define _test_SDPCommunicator_h

#include <nemesis.Average.h>

#include <nemesis.sdp.Communicator.h>

namespace test {

using namespace nemesis;

class SDPCommunicator : public sdp::Communicator {
public:
   SDPCommunicator (sdp::Application& application, WorkMode::_v workmode = WorkMode::Single) : 
      sdp::Communicator (application, NULL, workmode),
      a_maxMessage (-1), 
      a_messageCounter (0), 
      a_successCounter (0),
      a_initTime (0),
      a_avgDelay ("AvgDelay"),
      a_delay (0),
      a_errorCounter (0)
   {;}
   
   void setDelay (const Milisecond delay) throw () { a_delay = delay; }
   void setMaxMessage (const int maxMessage) throw () { a_maxMessage = maxMessage; }
   
   int getMaxMessage () const throw () { return a_maxMessage; }
   int getMessage () const throw () { return a_messageCounter; }

   bool canContinue (const sdp::Interface*) throw (RuntimeException);
   void delay () throw (RuntimeException);   
   void notifyError () throw (RuntimeException);   
   void resetError () throw (RuntimeException);   
   
private:
   Milisecond a_delay;
   Milisecond a_initTime;
   int a_maxMessage;
   int a_messageCounter;
   int a_successCounter;
   Average <Microsecond> a_avgDelay;
   int a_errorCounter;
  
   // Permite ejecutar los procesos SDP sin tener que tener arrancado el GEVENTOS. 
   void eventStartup () throw () {
      try {
         sdp::Communicator::eventStartup ();
      }
      catch (RuntimeException& ex) {
         ex.trace ();
      }
   }

   void eventOverQuota (const comm::ClientSocket&) throw ();      
   void terminate () throw ();
};

}

#endif
